home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / D51_NUSource / Source / Singles / RexxSend.s < prev   
Text File  |  1996-01-06  |  16KB  |  350 lines

  1. *=- PROGRAM INFORMATION -=*************************************************************
  2. * NoSoSuper-RexxSend, ©1995 Leo Davidson                                              *
  3. *=====================================================================================*
  4. * Purpose: This program sends messages to a program's ARexx port and returns the      *
  5. *       results in a requester.                              *
  6. *          (Written to test my ARexx/rexxsyslib.library routines).              *
  7. ***************************************************************************************
  8.  
  9. *=- ASSEMBLE-TIME SWITCHES -=**********************************************************
  10. * Comment out to disable the effect(s) described.                                     *
  11. ***************************************************************************************
  12. ;Beta_Version        ; Include Debug-Labels, Beta messages, etc.
  13. Beta_Version_ARexx    ; Include runtime-info about ARexx messages sent.
  14. ;Test_Pool_On_OS3    ; Force use of non-ROM pool routines, even with OS3+.
  15. DOpus5_Error        ; Enable Error messages via DOpus5/"dopus request".
  16. ;No_Requesters        ; Disable all requester-based output.
  17.             ; All error messages will be sent to shell.
  18.             ; Will also turn off "Please insert volume XXX" reqs.
  19. ;Default_Req        ; Make requesters the default for error messages.
  20.  
  21. *=- VERSION INFORMATION -=*************************************************************
  22. * Things like versions numbers, dates, and the name of the program are all defined    *
  23. * here as macros to save having to edit the entire source code.                       *
  24. *=====================================================================================*
  25. * The version strings should conform to the style guide. (Even though I think it      *
  26. * isn't the best way to do it, it's a standard :-(  ).                                *
  27. ***************************************************************************************
  28. PROGNAM    MACRO                Program name.
  29.     dc.b    "NoSoSuper-RexxSend"    /No spaces!/
  30.     ENDM
  31. VERSION    MACRO                The version of the program.
  32.     dc.b    "1.5"            version.revision - /No leading zeros/
  33.     ENDM
  34. REVDATE    MACRO                Date of completion.
  35.     dc.b    "21.8.95"        DD.MM.YY - /No leading zeros/
  36.     ENDM
  37. REVDAT2    MACRO                Date of completion.
  38.     dc.b    "21-Aug-1995"        /Any format/ (Not in $VER string)
  39.     ENDM
  40. *=- ASSEMBLER INFORMATION/OPTIONS -=***************************************************
  41.     Section    Super_Main,Code        Assemble to Public Memory.
  42.     IFD    Beta_Version        -.
  43.     Opt    D+             |
  44.     Opt    hcln             |_ Debug info ON
  45.     ELSE                 |  for Beta Versions.
  46.     Opt    D-             |
  47.     ENDC                -'
  48. ***************************************************************************************
  49.     Bra    ProgBeg            Jump to the start of the program.
  50. ***************************************************************************************
  51. VerStr    Dc.b    "$VER: "        -.
  52.     PROGNAM                 |
  53.     IFD    Beta_Version         |
  54.     Dc.b    "_BETA"             |
  55.     ENDC                 |_ For 2.0+ Version Command
  56.     Dc.b    " "             |  (At the top to make "Version"
  57. ActVer    VERSION                 |  find it quicker!)
  58.     Dc.b    " ("             |
  59.     REVDATE                 |
  60.     Dc.b    ")",0            -'
  61.     Even
  62. ;=====================================================================================;
  63. ;    Include    Asm:Include/Nudel_Constants.i
  64. ;
  65. ;    include    dos/dos.i
  66. ;    include    dos/var.i
  67. ;    include    exec/types.i
  68. ;    include    exec/nodes.i
  69. ;    include    exec/memory.i
  70. ;    include    rexx/storage.i
  71. ;    include    intuition/intuition.i
  72. ;    include    intuition/intuitionbase.i
  73. ;    include    libraries/iffparse.i
  74. ;
  75. ;    include    ASM:LVO3.0/dos_lib.i
  76. ;    include    ASM:LVO3.0/exec_lib.i
  77. ;    include    ASM:LVO3.0/intuition_lib.i
  78. ;    include    ASM:LVO3.0/rexxsyslib_lib.i
  79. ;    include    ASM:LVO3.0/utility_lib.i
  80. ;    include    ASM:LVO3.0/iffparse_lib.i
  81. ;    include    ASM:LVO3.0/mathieeedoubbas_lib.i
  82. ;    include    ASM:LVO3.0/graphics_lib.i
  83.  
  84.     Include    Nudel_Symbols.gs
  85. ***************************************************************************************
  86. * The Variables (Address Equates for Space allocated at program start)                *
  87. ***************************************************************************************
  88.     RSReset
  89. ;=====================================================================================;
  90. N_DTStruc    Equ    __RS        ;- Date-Time Structure -----------------------;
  91. ;=====================================================================================;
  92. N_DT_Days    Rs.l    1        Days Since 1978
  93. N_DT_Mins    Rs.l    1        Mins Since Midnight
  94. N_DT_Tiks    Rs.l    1        Ticks Since Minute (Always Even*50)
  95. N_DT_4Mat    Rs.b    1        Format   -.
  96. N_DT_Flag    Rs.b    1        Flags     |
  97. N_DT_Name    Rs.l    1        Date Adr  |- For Outputting.
  98. N_DT_Date    Rs.l    1        Name Adr  |
  99. N_DT_Time    Rs.l    1        Time Adr -'
  100. ;- End of DTStruc --------------------------------------------------------------------;
  101. D8_Name        Rs.b    16        Name String    -.
  102. D8_Date        Rs.b    16        Date String     |- Output buffers.
  103. D8_Time        Rs.b    16        Time String    -'
  104.  
  105.     IFND    No_Requesters
  106. ;=====================================================================================;
  107. N_EasyStruct    Equ    __RS        ;- EasyStruct for EasyRequest ----------------;
  108. ;=====================================================================================;
  109. N_ES_Length    Rs.l    1        Length of the structure.
  110. N_ES_Flags    Rs.l    1        Flags (not currently supported).
  111. N_ES_Title    Rs.l    1        Ptr to NullTerm Title Text.
  112. N_ES_Body    Rs.l    1        Ptr to NullTerm Body Text.
  113. N_ES_Gadgets    Rs.l    1        Prt to Gadget(s) Texts.
  114. N_EasyStruct_Len    Equ    (__RS)-N_EasyStruct
  115.     ENDC
  116.  
  117. ;=====================================================================================;
  118. ; Nudel Info-Block Stuff                                  ;
  119. ;=====================================================================================;
  120. FakeNIB        Rs.b    NIB_SizeOf    ;- Fake NIB for setting pseudo-filenames -----;
  121. FakeNIB_Adrs    Rs.l    1        Address of FakeNIB (saves a few "lea"'s).
  122. Active_NIB    Rs.l    1        Ptr to currently "Active" NIB, or null.
  123. Base_NIB    Rs.l    1        Ptr to base NIB in linked list, or null.
  124. Last_NIB    Rs.l    1        Ptr to last NIB in linked list, or null.
  125. CAction        Rs.l    1        Ptr to current "Action" error message.
  126. ;=====================================================================================;
  127.  
  128. ;=====================================================================================;
  129. ; READARGS() STUFF                                      ;
  130. ;=====================================================================================;
  131. RDA_Rtn        Rs.l    1        Pointer to returned RDArgs structure
  132. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  133. RDA_Array    Equ    __RS        Array of longwords matching template
  134. RDA_Template    Equ    *
  135. RexxPort_A    Rs.l    1
  136.         Dc.b    "RP=REXXPORT/A,"
  137. RexxCommand_A    Rs.l    1
  138.         Dc.b    "RC=REXXCOMMAND/A,"
  139. Reqs_S        Rs.l    1
  140.         Dc.b    "REQ=REQS/S"
  141. RDA_Temp_Len    Equ    *-RDA_Template
  142.         Dc.b    0
  143.         Even
  144. ;=====================================================================================;
  145. ; OPEN_LIBRARIES STRUCTURES                                  ;
  146. ;=====================================================================================;
  147. LibBases_Start    Equ    __RS
  148. LibData_Start    Equ    *
  149. ; NOTE: The open_lib_error routine requires lib-versions < 100
  150. N_DOSBase    Rs.l    1
  151. DOSName_Ptr    Dc.l    N_DOSName-LibNames_Start
  152. DOSVers        Dc.l    37
  153. N_RexBase    Rs.l    1
  154. RexName_Ptr    Dc.l    N_RexName-LibNames_Start
  155. RexVers        Dc.l    0
  156.     IFND    No_Requesters
  157. N_IntBase    Rs.l    1
  158. IntBase_Ptr    Dc.l    N_IntName-LibNames_Start
  159. IntVers        Dc.l    37
  160.     ENDC
  161. LibBases_Finish    Equ    __RS
  162. NumLibs    Equ    (LibBases_Finish-LibBases_Start)/4
  163. ;-------------------------------------------------------------------------------------;
  164. LibNames_Start    Equ    *
  165. N_DOSName    DOSNAME
  166. N_RexName    REXXSYSLIBNAME
  167.     IFND    No_Requesters
  168. N_IntName    INTNAME        Required by Open_Libraries_Error rtn.
  169.     ENDC
  170.     Even
  171. ;=====================================================================================;
  172. ; FLAG BYTES                                          ;
  173. ;=====================================================================================;
  174. STD_F_1        Rs.b    1        Standard files.
  175. EVEN_F_1    Rs.b    1        (Here as an Even)
  176. ;=====================================================================================;
  177. ; VARIOUS DATA                                          ;
  178. ;=====================================================================================;
  179. DosRtnC        Rs.l    1        Return code for DOS. (-> d0 at end)
  180. ;=====================================================================================;
  181. ; RawDoFmt() Stuff                                      ;
  182. ;=====================================================================================;
  183. ;    IFD    DATA_RAWDOFMT
  184. RDF_Size    Rs.l    1        Size of RawDoFmt() buffer.
  185. RDF_Adrs    Rs.l    1        Address of RawDoFmt() buffer.
  186. RDF_Array    Equ    __RS
  187. RDF_1_Long    Rs.l    1        -.
  188. RDF_2_Long    Rs.l    1         |_ DataArray for
  189. RDF_3_Long    Rs.l    1         |  RawDoFmt()
  190. RDF_4_Long    Rs.l    1        -'
  191. ;    ENDC
  192. ;=====================================================================================;
  193. ; VARIOUS ADDRESS-POINTERS                                  ;
  194. ;=====================================================================================;
  195. StarStk        Rs.l    1        Original Stack Pointer.
  196. PoolHead    Rs.l    1        Header for program's memory pool.
  197. CLI_Hdl        Rs.l    1        Output CLI (or whatever) handle.
  198. NudelPort    Rs.l    1        Pointer to our MsgPort.
  199. NudelRexxMsg    Rs.l    1        Pointer to our RexxMsg.
  200. CRexxPort    Rs.l    1        Ptr to name of current Rexx host to talk to.
  201. ;=====================================================================================;
  202. ; TEMP STORAGE                                          ;
  203. ;=====================================================================================;
  204. Buffer1Len    Equ    1024
  205. Buffer1        Rs.b    Buffer1Len    Buffer for anything
  206. Buffer2Len    Equ    1024
  207. Buffer2        Rs.b    Buffer2Len    Buffer for anything
  208. BufferALen    Equ    1024
  209. BufferA        Rs.b    BufferALen    Buffer for anything
  210. Temp001        Rs.l    1        -._ For temp storage
  211. Temp002        Rs.l    1        -'  in routines.
  212. ;=====================================================================================;
  213. NULLEND        Equ    __RS        ;- Overlays Start Here -----------------------;
  214. ;=====================================================================================;
  215. ;=====================================================================================;
  216. LENVARS        Equ    __RS        ;- End of variables/overlays -----------------;
  217. ;=====================================================================================;
  218.  
  219. *=- MAIN PROGRAM -=********************************************************************
  220. * Calls the subroutines.                                  *
  221. ***************************************************************************************
  222. ProgBeg    Bsr.s    Setup            Allocate Mem and initialize stuff.
  223.  
  224.     Move.l    RexxCommand_A(a5),a1    Point to the command.
  225.     Bsr    FillAndSendNudelRexxMsg    Send it off.
  226.  
  227.     Bra.s    Finish            Close/Deallocate everything and exit.
  228.  
  229. *=- SETUP -=***************************************************************************
  230. * Allocate Memory, Open Libraries, Parse Commandline, etc                  *
  231. * This MUST be the first Subroutine run.                          *
  232. ***************************************************************************************
  233. Setup    Move.l    #Memf_Public!Memf_Clear,d0    Public, Cleared mem.
  234.     Move.l    #5120,d1            Puddle size = 5k.
  235.     Move.l    #5120,d2            Thresh size = Puddle size.
  236.     Bsr    AsmCreatePool            Create this prog's mem pool.
  237.     Move.l    a0,-(SP)        Preserve PoolHeader
  238.     Bne.s    SGotMm1            -.
  239.     Addq.l    #4,a7             |_ If Allocation failed, Quick Exit.
  240.     Moveq    #RETURN_FAIL,d0         |  pool and do a quick exit.
  241.     RTS                -'
  242. SGotMm1    Move.l    #LENVARS,d0        Size of variables' memory
  243. ;;;;;;;    Move.l    a0,a0            PoolHeader to a0 for allocation.
  244.     Bsr    AsmAllocPooled        Allocate for the variables.
  245.     Move.l    (SP)+,a0        Restore PoolHeader
  246.     Move.l    d0,a5            Put variable/overlay address into A5
  247.     Tst.l    d0            (Moves to a? don't set CCR).
  248.     Bne.s    SGotMm2            -.
  249.     Bsr    AsmDeletePool         |
  250.     Addq.l    #4,a7             |- If Allocation failed, delete the
  251.     Moveq    #RETURN_FAIL,d0         |  pool and do a quick exit.
  252.     RTS                -'
  253. SGotMm2    Move.l    a0,PoolHead(a5)        Store header of memory pool.
  254.     Lea    FakeNIB(a5),a0        -._ Store address of FakeNIB(a5)
  255.     Move.l    a0,FakeNIB_Adrs(a5)    -'  for quick access later.
  256.     Move.l    #RETURN_OK,DosRtnC(a5)    Default DOS return code: "OK".
  257.     IFD    LENOVER
  258.     Lea    NULLEND(a5),a0        -.
  259.     Lea    Over01(pc),a1         |  Copy Overlay
  260.     Move.l    #(LENOVER/2)-1,d0     |- Backings onto
  261. OverPrL    Move.w    (a1)+,(a0)+         |  Overlay Space (word moves)
  262.     DBra    d0,OverPrL        -'
  263.     ENDC
  264. ;=====================================================================================;
  265.     Move.l    a7,StarStk(a5)        Store Stack Pointer
  266.     Addq.l    #4,StarStk(a5)        Compensate for this being a subrout.
  267.     IFND    No_Requesters
  268.     SetReqDefault            Set default to requester/shell.
  269.     ENDC
  270.     Bsr    Open_Libraries        Open libraries.
  271.     N_CallDOS    Output        -._ Get output Handle
  272.     Move.l    d0,CLI_Hdl(a5)        -'  (CLI window or whatever)
  273.  
  274. ;;;;;;;    Setup any non-zero default values for switch options here (below).
  275.     Bsr    RArgNor            Parse the commandline with ReadArgs
  276.  
  277.     Move.l    RexxPort_A(a5),CRexxPort(a5)    Use RexxPort from CmdLine.
  278.  
  279.     Bsr.s    CreateNudelPort        Create our MsgPort.
  280.     RTS
  281.  
  282. *=- FINISH -=**************************************************************************
  283. * Close Everything Down, Return Memory Etc to System and End Program              *
  284. *=====================================================================================*
  285. * All routines in this section MUST make sure that what they are about to free back   *
  286. * to the system has actually been taken in the first place! (With the exception of    *
  287. * the Main-Variable memory: if this could not be allocated the program will have      *
  288. * quit without calling Finish.)                                  *
  289. *=====================================================================================*
  290. * The Finish routine may be called from sub-routines at any level because the          *
  291. * original stack-pointer is restored so that RTS always quits the prog.              *
  292. ***************************************************************************************
  293. Finish
  294.     IFD    Beta_Version
  295.     Bsr_ErrorN    ErrAct_FinishBetaMsg(pc),#0
  296.     ENDC
  297.  
  298.     Bsr    DeleteNudelRexxMsg    Delete our RexxMsg (also clears arguments).
  299.     Bsr.s    DeleteNudelPort        Delete our MsgPort
  300. ;;;;;;;    Bsr    NIBs_DeleteAll        Delete all Nudel-Info-Blocks :-)
  301.     Bsr    FArgNor            Free the commandline related memory.
  302.     Bsr    Close_Libraries        Close all open libraries.
  303.     Move.l    StarStk(a5),a7        Ignore all Branches.
  304.     Move.l    DosRtnC(a5),-(SP)    Store DOS return code...
  305.     Bsr    LeoDeletePool        Free the entire memory pool.
  306.     Move.l    (SP)+,d0        Return code to d0 for DOS.
  307.     RTS                End Program
  308.  
  309.     IFD    Beta_Version
  310. ErrAct_FinishBetaMsg
  311.     Dc.b    "Finish routine run",0
  312.     Even
  313.     ENDC
  314.  
  315. *=- EXTERNAL SUB-ROUTINES -=***********************************************************
  316. * Sub-routines stored in external "library" files.                      *
  317. ***************************************************************************************
  318. ;=====================================================================================;
  319. ; OS Subroutines                                      ;
  320. ;=====================================================================================;
  321. SYS_CLIRITE    ; Write text using CLI_Hdl(a5) as output handle.
  322. SYS_READARG    ; ReadArgs() routine.
  323. SYS_FREEARG    ; FreeArgs() routine.
  324. SYS_CHKCRTC    ; Check for ^C-Break and abort program if sent.
  325. SYS_PORTS    ; CreateMsgPort(), DeleteMsgPort() routines.
  326.     Include    ASM:Source/Routines/System.s
  327. ;=====================================================================================;
  328. ; Data Subroutines. (Number/String Handling, etc etc)                      ;
  329. ;=====================================================================================;
  330. DATA_NULLLEN    ; Calculate the length of a Null-Term String.
  331. DATA_COPYCN3    ; Copy chars with Null-Term, don't copy Null, no Length
  332. DATA_CHARCNT    ; Copy x chars with Null-Term
  333. DATA_CHARCOP    ; Copy x chars with specified terminator.
  334. DATA_CHARCOPNL
  335. DATA_NUM2ASC    ; Raw Number to ASCII conversion.
  336. DATA_RAWDOFMT    ; RawDoFmt() routine.
  337.     Include    ASM:Source/Routines/Data.s
  338. ;=====================================================================================;
  339. ; Other routines.                                      ;
  340. ;=====================================================================================;
  341.     Include    ASM:Source/Routines/ARexx.s
  342.     Include    ASM:Source/Routines/Pool.s
  343.     Include    ASM:Source/Routines/OpenLibraries.s
  344. ;;;;;;;    Include    ASM:Source/Routines/NIB.s
  345. ; Note: NIB_DeleteAll has been removed from Finish.
  346. ***************************************************************************************
  347. * THE END                                          *
  348. ***************************************************************************************
  349.  
  350.